import cPickle,sqlite3,sys
from evedb import base,defs,solar

conn=sqlite3.connect('dom100-sqlite3-v1.db')
curs=conn.cursor()

db=base.dbDatabase(curs)

curs.execute('SELECT itemId,itemName FROM eveNames')
db['dbName']=dict(curs.fetchall())
print ' - Loaded',len(db['dbName']),'names.'

db.doImport(defs.Faction)
db.doImport(defs.Corp)
db.doImport(defs.Division)
db.doImport(solar.SolarSys)
db.doImport(defs.Station)
db.doImport(defs.AgentType)
#db.doImport(defs.Location)
db.doImport(defs.Agent)

del db['dbName'] #no need for them to be exported, lots of crap

db.SolarName=dict((s.name,s) for s in db.SolarSys.values())
print ' - Built Name index for Solar Systems'

curs.execute('SELECT fromSolarSystemID,toSolarSystemID FROM mapSolarSystemJumps')
for f,t in curs.fetchall():
    db.SolarSys[f].links.append(db.SolarSys[t])
print ' - Loaded links'

del(db.cursor)

sys.setrecursionlimit(100000)
with file('eve.db','wb') as f:
    cPickle.dump(db,f,2)
print ' - All done'
